package top.kaoshanji.p2ch06a;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.sql.*;

/**
 * 代码清单 p2ch06a-02：setSchema方法的使用示例
 * author kaoshanji
 * ^_^
 * create time 2025/1/17 15:50
 */
public class ConnectionExample01 {

    private static final Logger logger = LogManager.getLogger(ConnectionExample01.class);

    public static void main(String[] args) {
        logger.info("...代码清单 p2ch06a-02：setSchema方法的使用示例...");

        try (Connection connection = DriverManager.getConnection("jdbc:derby://localhost/p2-java7book")){
            connection.setSchema("DEMO_SCHEMA"); // 设置默认的模式...然后再是后面的
            try (Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM author")){
                while (rs.next()) {
                    System.out.println(rs.getString("name"));
                }
            }

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }


    }

}
